package com.lee;

import com.lee.mybatis.entity.User;
import com.lee.spring.service.impl.UserServiceImpl;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.text.SimpleDateFormat;
import java.util.Date;


@Slf4j
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/app-exam.xml")
public class Usertest {

    @Autowired
    private UserServiceImpl userServiceImpl;

    @Test
    public void login(){
        log.info("输出：{}",userServiceImpl.login("admin","123"));
    }

    @SneakyThrows
    @Test
    public void insert(){

        Date date = new SimpleDateFormat("yyyy-MM-dd").parse("1999-08-07");
        User user = new User(5,5,"李欣美","1234","李大王",0,"17382842596","宇宙第一",date,null,null,null);
        userServiceImpl.insert(user);
    }

    @SneakyThrows
    @Test
    public void updateById() {

        Date date = new SimpleDateFormat("yyyy-MM-dd").parse("1999-08-07");
        User user = new User(5,5,"李欣美","1234","李香香",0,"17382842596","宇宙第一",date,null,null,null);
        userServiceImpl.updateById(user);
    }

    @Test
    public void deleteById(){
        userServiceImpl.deleteById(5);
    }

    @Test
    public void selectWithUserNo(){
        for (User user:
                userServiceImpl.selectWithUserNo()) {
            log.info("user:{}",user);
        }
    }

    @Test
    public void selectByUserId(){
        log.info("输出：{}",userServiceImpl.selectByUserId(2));

    }
}
